var version = "20170310";
var location_pathname = location.pathname;
/*封装基本参数*/
var Base_puhui = {
    //引入html对应目录相同的css和js
    quoteCssAndJsCurrent: function (backQuite) {
        quoteJsBase(getLocationPathname("js"));
        quoteCssBase(getLocationPathname("css"));
        if(backQuite!=undefined){
           eval(backQuite+"()")
        }
    },
    separator:","
}

function getLocationPathname(suffix) {

    if (isNull(suffix)) {
        return;
    }

    var html_relative = location_pathname.substring(location_pathname.indexOf("/pages") + 7);

    return getRelativeWithStatic() +suffix+"/" +html_relative.replace(".html", "." + suffix);
}

/*返回当前html返回到static目录的../ 用于引用路径*/
function getRelativeWithStatic() {
    var last_path = "../";
    var relative_path = "";
    var relative_length = location_pathname.replace(/\w/g, '').split("/").length - 4;
    for (var i = 0; i < relative_length; i++) {
        relative_path += last_path;
    }
    return relative_path;
}

/*引用js基础方法 可以传入批量的js src*/
function quoteJsBase(srcs) {
    quoteJsOrCssBase("js", srcs);
}

/*引用css基础方法 可以传入批量的css href*/
function quoteCssBase(hrefs) {
    quoteJsOrCssBase("css", hrefs);
}

//引用加入js或者css
function quoteJsOrCssBase(jsOrCss, src) {

    if (isNullWithFixedStr(jsOrCss, ["css", "js"])) {
        return;
    }

    if (src instanceof Array) {
        for (var i = 0; i < src.length; i++) {
            jsOrCss == "css" ? loadStyleString(src[i]) :loadScriptString(src[i]) ;
        }
    } else {
        jsOrCss == "css" ? loadStyleString(src) :loadScriptString(src) ;
    }
}

// 动态加载js脚本
function loadScriptString(src) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = src;
    document.body.appendChild(script);
}

// 动态加载css脚本
function loadStyleString(href) {
    var link = document.createElement("link");
    link.setAttribute("rel", "stylesheet");
    link.setAttribute("type", "text/css");
    link.setAttribute("href", href);
    document.getElementsByTagName("head")[0].appendChild(link);
}


